﻿using System;

namespace Example.Presentation.Kernel
{
    /// <summary>
    /// Used to resolve dependencies in the application
    /// </summary>
    public static class ServiceLocator
    {
        /// <summary>
        /// Default Dependency resolver
        /// </summary>
        private static IDependencyResolver _resolver = new NinjectDependencyResolver();

        /// <summary>
        /// Registers a new dependency resolver (ie for unit testing)
        /// </summary>
        /// <param name="resolver"></param>
        public static void RegisterResolver(IDependencyResolver resolver) 
        {
            _resolver = resolver; 
        }    
        
        /// <summary>
        /// Disposes the current dependency resolver
        /// </summary>
        public static void DisposeResolver()
        {
            _resolver.Dispose();
        }

        /// <summary>
        /// Resolves the requested type using the current dependency resolver
        /// </summary>
        public static TType Resolve<TType>()
        {
            return _resolver.GetImplementationOf<TType>();
        }
    }
}
